<!-- capture version from first argument in "skew" -->
{{- $version := .Get 0 -}}

<!-- strip "v" from latest verison  -->
{{- $latestVersion := site.Params.latest -}}
{{- $latestVersion := (replace $latestVersion "v" "") -}}

<!-- splits a string x.Xy into substrings separated by a "." delimiter  -->
{{- $versionArray := split $latestVersion "." -}}

<!-- capture minorVersion ("Xy") in a variable -->
{{- $minorVersion := int (index $versionArray 1) -}}

<!-- increment latest 1 minor number for "nextMinorVerison" -->
{{- $nextMinorVersion := add $minorVersion 1 -}}

<!-- subtract latest 1 minor number for "prevMinorVerison" -->
{{- $prevMinorVersion := sub $minorVersion 1 -}}

<!-- subtract latest 2 minor numbers for "oldestMinorVerison" -->
{{- $oldestMinorVersion := sub $minorVersion 2 -}}

<!-- output nextMinorVersion based on captured arg -->
{{- if eq $version "nextMinorVersion" -}}
    {{- $nextMinorVersion := printf "%s.%d" (index $versionArray 0) $nextMinorVersion -}}
    {{- $nextMinorVersion -}}
{{- end -}}

<!-- output latestVersion based on captured arg -->
{{- if eq $version "latestVersion" -}}
    {{- $latestVersion -}}
{{- end -}}

<!-- output prevMinorVersion based on captured arg -->
{{- if eq $version "prevMinorVersion" -}}
    {{- $prevMinorVersion := printf "%s.%d" (index $versionArray 0) $prevMinorVersion -}}
    {{- $prevMinorVersion -}}
{{- end -}}

<!-- output oldestMinorVersion based on captured arg -->
{{- if eq $version "oldestMinorVersion" -}}
    {{- $oldestMinorVersion := printf "%s.%d" (index $versionArray 0) $oldestMinorVersion -}}
    {{- $oldestMinorVersion -}}
{{- end -}}

<!-- output latestVersionAddMinor based on captured args -->
{{- if eq $version "latestVersionAddMinor" -}}
    {{- $seperator := .Get 2 -}}
    {{- if eq $seperator "" -}}
        {{- $seperator = "." -}}
    {{- end -}}
    {{- $latestVersionAddMinor := int (.Get 1) -}}
    {{- $latestVersionAddMinor = add $minorVersion $latestVersionAddMinor -}}
    {{- $latestVersionAddMinor = printf "%s%s%d" (index $versionArray 0) $seperator $latestVersionAddMinor -}}
    {{- $latestVersionAddMinor -}}
{{- end -}}

{{- $currentVersion := site.Params.version -}}
{{- $currentVersion := (replace $currentVersion "v" "") -}}
{{- $currentVersionArray := split $currentVersion "." -}}
{{- $currentMinorVersion := int (index $currentVersionArray 1) -}}

<!-- output latestVersion based on captured arg -->
{{- if eq $version "currentVersion" -}}
    {{- $currentVersion -}}
{{- end -}}

<!-- output currentVersionAddMinor based on captured args -->
{{- if eq $version "currentVersionAddMinor" -}}
    {{- $seperator := .Get 2 -}}
    {{- if eq $seperator "" -}}
        {{- $seperator = "." -}}
    {{- end -}}
    {{- $currentVersionAddMinor := int (.Get 1) -}}
    {{- $currentVersionAddMinor = add $currentMinorVersion $currentVersionAddMinor -}}
    {{- $currentVersionAddMinor = printf "%s%s%d" (index $versionArray 0) $seperator $currentVersionAddMinor -}}
    {{- $currentVersionAddMinor -}}
{{- end -}}

<!-- output patch version for current release -->
{{- if eq $version "currentPatchVersion" -}}
    {{- $seenPatchVersionInfoCount := 0 }}
    {{- range $releaseInfo := .Site.Data.releases.schedule.schedules -}}
        {{- if eq $currentVersion ( printf "%.2f" $releaseInfo.release ) -}}
            {{- range $patchReleaseInfo := $releaseInfo.previousPatches -}}
                {{- if eq $seenPatchVersionInfoCount 0 -}}
                  {{- $patchReleaseInfo.release -}}
                {{- end -}}
                {{- $seenPatchVersionInfoCount = add $seenPatchVersionInfoCount 1 -}}
            {{- end -}}
        {{- end -}}
    {{- end -}}
    {{- if eq $seenPatchVersionInfoCount 0 -}}
        <!-- fallback patch version to .0 -->
        {{- printf "%.2f.0" $currentVersion -}}
    {{- end -}}
{{- end -}}

<!--
example shortcode use:
- skew nextMinorVersion
- skew latestVersion
- skew currentVersion
- skew prevMinorVersion
- skew oldestMinorVersion
- skew latestVersionAddMinor -1 "-"
- skew currentVersionAddMinor -1 "-"
-->